using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace Medianamik.SubsonicDALProvider.DAL
{
	/// <summary>
	/// Strongly-typed collection for the ModuleType class.
	/// </summary>
	[Serializable]
	public partial class ModuleTypeCollection : ActiveList<ModuleType,ModuleTypeCollection> 
	{	   
		public ModuleTypeCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the medianamik_ModuleType table.
	/// </summary>
	[Serializable]
	public partial class ModuleType : ActiveRecord<ModuleType>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public ModuleType()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public ModuleType(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

        
		public ModuleType(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public ModuleType(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}

		
		protected static void SetSQLProps() { GetTableSchema(); }

		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }

		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}

		}

		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("medianamik_ModuleType", TableType.Table, DataService.GetInstance("MedianamikProvider"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarModuleTypeId = new TableSchema.TableColumn(schema);
				colvarModuleTypeId.ColumnName = "ModuleTypeId";
				colvarModuleTypeId.DataType = DbType.Guid;
				colvarModuleTypeId.MaxLength = 0;
				colvarModuleTypeId.AutoIncrement = false;
				colvarModuleTypeId.IsNullable = false;
				colvarModuleTypeId.IsPrimaryKey = true;
				colvarModuleTypeId.IsForeignKey = false;
				colvarModuleTypeId.IsReadOnly = false;
				colvarModuleTypeId.DefaultSetting = @"";
				colvarModuleTypeId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarModuleTypeId);
				
				TableSchema.TableColumn colvarTypeId = new TableSchema.TableColumn(schema);
				colvarTypeId.ColumnName = "TypeId";
				colvarTypeId.DataType = DbType.Guid;
				colvarTypeId.MaxLength = 0;
				colvarTypeId.AutoIncrement = false;
				colvarTypeId.IsNullable = false;
				colvarTypeId.IsPrimaryKey = false;
				colvarTypeId.IsForeignKey = true;
				colvarTypeId.IsReadOnly = false;
				colvarTypeId.DefaultSetting = @"";
				
					colvarTypeId.ForeignKeyTableName = "medianamik_Type";
				schema.Columns.Add(colvarTypeId);
				
				TableSchema.TableColumn colvarModuleId = new TableSchema.TableColumn(schema);
				colvarModuleId.ColumnName = "ModuleId";
				colvarModuleId.DataType = DbType.Guid;
				colvarModuleId.MaxLength = 0;
				colvarModuleId.AutoIncrement = false;
				colvarModuleId.IsNullable = false;
				colvarModuleId.IsPrimaryKey = false;
				colvarModuleId.IsForeignKey = true;
				colvarModuleId.IsReadOnly = false;
				colvarModuleId.DefaultSetting = @"";
				
					colvarModuleId.ForeignKeyTableName = "medianamik_Module";
				schema.Columns.Add(colvarModuleId);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["MedianamikProvider"].AddSchema("medianamik_ModuleType",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("ModuleTypeId")]
		public Guid ModuleTypeId 
		{
			get { return GetColumnValue<Guid>(Columns.ModuleTypeId); }

			set { SetColumnValue(Columns.ModuleTypeId, value); }

		}

		  
		[XmlAttribute("TypeId")]
		public Guid TypeId 
		{
			get { return GetColumnValue<Guid>(Columns.TypeId); }

			set { SetColumnValue(Columns.TypeId, value); }

		}

		  
		[XmlAttribute("ModuleId")]
		public Guid ModuleId 
		{
			get { return GetColumnValue<Guid>(Columns.ModuleId); }

			set { SetColumnValue(Columns.ModuleId, value); }

		}

		
		#endregion
		
		
			
		
		#region ForeignKey Properties
		
		/// <summary>
		/// Returns a ModuleX ActiveRecord object related to this ModuleType
		/// 
		/// </summary>
		public Medianamik.SubsonicDALProvider.DAL.ModuleX ModuleX
		{
			get { return Medianamik.SubsonicDALProvider.DAL.ModuleX.FetchByID(this.ModuleId); }

			set { SetColumnValue("ModuleId", value.ModuleId); }

		}

		
		
		/// <summary>
		/// Returns a Type ActiveRecord object related to this ModuleType
		/// 
		/// </summary>
		public Medianamik.SubsonicDALProvider.DAL.Type Type
		{
			get { return Medianamik.SubsonicDALProvider.DAL.Type.FetchByID(this.TypeId); }

			set { SetColumnValue("TypeId", value.TypeId); }

		}

		
		
		#endregion
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(Guid varModuleTypeId,Guid varTypeId,Guid varModuleId)
		{
			ModuleType item = new ModuleType();
			
			item.ModuleTypeId = varModuleTypeId;
			
			item.TypeId = varTypeId;
			
			item.ModuleId = varModuleId;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(Guid varModuleTypeId,Guid varTypeId,Guid varModuleId)
		{
			ModuleType item = new ModuleType();
			
				item.ModuleTypeId = varModuleTypeId;
			
				item.TypeId = varTypeId;
			
				item.ModuleId = varModuleId;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn ModuleTypeIdColumn
        {
            get { return Schema.Columns[0]; }

        }

        
        
        
        public static TableSchema.TableColumn TypeIdColumn
        {
            get { return Schema.Columns[1]; }

        }

        
        
        
        public static TableSchema.TableColumn ModuleIdColumn
        {
            get { return Schema.Columns[2]; }

        }

        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string ModuleTypeId = @"ModuleTypeId";
			 public static string TypeId = @"TypeId";
			 public static string ModuleId = @"ModuleId";
						
		}

		#endregion
		
		
		
	}

}

